import React, { Component, createRef } from 'react';

class Ref extends Component {
  constructor() {
    super();
    this.state = {

    }
    // 创建ref
    this.divRef = createRef()
  }
  componentDidMount() {
    // 等待dom更新后  再获取ref
    console.log(this.divRef.current.innerHTML);
    this.divRef.current.innerHTML = 666
  }
  render() {
    return (
      <div>
        <div ref={this.divRef} className="div1">div1</div>
      </div>
    );
  }
}

export default Ref;
